// /home/stoner/code/sanfs/MediaChanger/TestMySqlDataStoreDriver.cs created with MonoDevelop
// User: stoner at 6:57 PM 5/28/2007
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using SanFS.DiscLibrary;
using NUnit.Framework;


namespace SanFS.MediaChangerLibrary
{
	#if false
	
	[TestFixture()]
	public class TestMySqlDataStoreDriver
	{
	    private IDataStore  mData = null;
	    
		[SetUp]
	    public void Init()
	    {
	        mData = DataStoreFactory.CreateDataStore("ds:MySqlDataStoreDriver:192.168.77.100:sanfs:mythtv:mythtv");
	    }
	    
	    [Test()]
	    public void TestConnect()
	    {
	        mData.Connect();
	    }
	    
	    [Test()]
	    public void TestReadBothElementLists()
	    {
            mData.Connect();
            List<IStorageElement> seList = mData.GetStorageElementList();
            List<IDisc> dList = mData.GetDiscList();
	    }
	    
		[Test()]
		public void TestSaveRestoreStorageElementList()
		{
			IStorageElement foo =
				new StorageElement(1, ElementType.Normal, true, Guid.Empty);
			
			List<IStorageElement> elements = 
				new List<IStorageElement>();
				
			
									
			elements.Add(new StorageElement(0, ElementType.Normal, true, Guid.Empty));
			elements.Add(new StorageElement(1, ElementType.DataTransfer, true, Guid.Empty));
			elements.Add(new StorageElement(3, ElementType.ImportExport, true, Guid.Empty));
			elements.Add(new StorageElement(4, ElementType.DataTransfer, false, Guid.Empty));
			elements.Add(new StorageElement(7, ElementType.Normal, false, Guid.Empty));
			
			
			Console.WriteLine("Connecting");
			mData.Connect();
			Console.WriteLine("Initializing");
			mData.Initialize();
			Console.WriteLine("Saving storage list");
			mData.SaveStorageElementList(elements);			
			Console.WriteLine("Getting storage list");						
			List<IStorageElement> elementsReturn =
				mData.GetStorageElementList();
			Console.WriteLine("Comparing storage list");
			for(int count = 0; count < 5; count++) {
				Assert.AreEqual(
					elements[count].Empty,
					elementsReturn[count].Empty
				);
				Assert.AreEqual(
					elements[count].Slot,
					elementsReturn[count].Slot
				);
				Assert.AreEqual(
					elements[count].Type,
					elementsReturn[count].Type
				);
			}
			
			mData.Disconnect();			
			
		}
		
		[Test()]
		public void TestSaveRestoreDiscList()
		{			
			List<IDisc> discs =
				new List<IDisc>();
			
			List<IDiscFile> files = new List<IDiscFile>();
			
			files.Add(new DiscFile(Guid.NewGuid(), 1231245,
				1, "/foo/bar", 1, 156, 124));
			files.Add(new DiscFile(Guid.NewGuid(), 123235,
				3, "/foz/baz", 3, 1235, 1234));
				
			discs.Add(new Disc(EDiscType.DVD, false, EDiscStatus.Complete, 
				123412342342L, 1241451L, 100, Guid.NewGuid(), 1, files));
			
			List<IDiscFile> files2 = new List<IDiscFile>();
			
			files2.Add(new DiscFile(Guid.NewGuid(), 613515,
				6, "/foq/bae", 2, 11246, 111));
			files2.Add(new DiscFile(Guid.NewGuid(), 566132,
				2, "/fow/bat", 555, 12235125, 1212344));
			
			discs.Add(new Disc(EDiscType.CD, true, EDiscStatus.Complete, 
				1234123423125L, 1123512341451L, 150, Guid.NewGuid(), 2, files2));
		
			
			
			mData.Connect();
			mData.Initialize();
			mData.SaveDiscList(discs);			
						
			List<IDisc> discReturn =
				mData.GetDiscList();
				
			for(int count = 0; count < 2; count++) {
				Console.WriteLine("Testing disc " + count);
				Assert.AreEqual(
					discReturn[count].FreeSpace,
					discs[count].FreeSpace
				);
				Assert.AreEqual(
					discReturn[count].MaxWriteSpeed,
					discs[count].MaxWriteSpeed
				);				
				Assert.AreEqual(
					discReturn[count].Rewritable,
					discs[count].Rewritable
				);				
				Assert.AreEqual(
					discReturn[count].Status,
					discs[count].Status
				);				
				Assert.AreEqual(
					discReturn[count].TotalSize,
					discs[count].TotalSize
				);				
				Assert.AreEqual(
					discReturn[count].Type,
					discs[count].Type
				);				
				Assert.AreEqual(
					discReturn[count].Uuid,
					discs[count].Uuid
				);				
				Assert.AreEqual(
					discReturn[count].Version,
					discs[count].Version
				);		
				for (int count2 = 0; count2 < discs[count].Files.Count; count2++) {
					Console.WriteLine("Testing disc " + count + ", discFile " + count2);
					Assert.AreEqual(
						discs[count].Files[count2].ChunkNumber,
						discReturn[count].Files[count2].ChunkNumber
					);
					Assert.AreEqual(
						discs[count].Files[count2].ChunkOffset,
						discReturn[count].Files[count2].ChunkOffset
					);
					Assert.AreEqual(
						discs[count].Files[count2].ChunkSize,
						discReturn[count].Files[count2].ChunkSize
					);
					Assert.AreEqual(
						discs[count].Files[count2].Path,
						discReturn[count].Files[count2].Path
					);
					Assert.AreEqual(
						discs[count].Files[count2].TotalChunks,
						discReturn[count].Files[count2].TotalChunks
					);
					Assert.AreEqual(
						discs[count].Files[count2].TotalSize,
						discReturn[count].Files[count2].TotalSize
					);
					Assert.AreEqual(
						discs[count].Files[count2].Uuid,
						discReturn[count].Files[count2].Uuid
					);
				}
				
			}			
			
			mData.Disconnect();					
		}
	}
	#endif
}
